package com.ml.springboot.controller;

import com.ml.springboot.pojo.LeaveType;
import com.ml.springboot.pojo.VO.LeaveTypeVO;
import com.ml.springboot.pojo.query.BlogTypeQuery;
import com.ml.springboot.service.ILeaveTypeService;
import com.ml.springboot.util.PageResult;
import com.ml.springboot.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/leaveType")
public class LeaveTypeController {
/*    @Autowired
    private BlogTypeMapper blogTypeMapper;*/
    @Autowired
    private ILeaveTypeService leaveTypeService;

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(BlogTypeQuery blogTypeQuery) {
        System.out.println("BlogTypeController.list");
        PageResult pageResult = leaveTypeService.list(blogTypeQuery);
        return pageResult;
    }



    @RequestMapping("/toLeaveTypeList")
    public String toBlogTypeList() {
        return "leave_type_list";
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public Result deletedById(Integer id) {
        leaveTypeService.deletedById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    @ResponseBody
    public Result deletedAll(Integer[] ids) {
        leaveTypeService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/toLeaveTypeAdd")
    public String toBlogTypeAdd() {
        return "leave_type_add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public Result add(LeaveType blogType) {
        leaveTypeService.add(blogType);
        return Result.ok("添加成功");
    }
    @RequestMapping("/selectAll")
    @ResponseBody
    public Result selectAll1() {
        List<LeaveTypeVO> list=leaveTypeService.selectAll();
        return Result.ok(list);
    }
    @RequestMapping("/toBlogTypeUpdate")
    public String toBlogTypeUpdate(LeaveType blogType) {
        return "blog_type_update";
    }

    @RequestMapping("/selectById")
    @ResponseBody
    public Result selectById(Integer id) {
        LeaveType blogType = leaveTypeService.selectById(id);
        return Result.ok(blogType);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Result update(LeaveType blogType) {
        leaveTypeService.update(blogType);
        return Result.ok("修改成功");
    }
}
